Skip to content

Add measure-preserving DuckDB views and speed up catalog discovery - #505

Merged
nicosuave merged 2 commits into
mainfrom
semantic-catalog-views
Nov 29, 2026
Merged

nicosuave merged 2 commits into
mainfrom
semantic-catalog-views

Conversation

@nicosuave

Copy link
Copy Markdown
Member

SQLCtx users can publish a selection of dimensions and measures with CREATE SEMANTIC VIEW. Queries of that view choose their own grain, including when the measures are filtered or ratios of aggregates. Named views support aliases, nesting, replacement, dependency checks, transaction rollback and database reopen. DuckDB 2.0.1 handles the declaration in its native PEG grammar. DuckDB 1.5.6 uses the compatibility parser.

The DuckDB extension also supports semantic queries through Python relations and the agent shell, resolves explicitly attached semantic models in their owning database, and returns SemanticInput results as a table. sqlctx_explain(sql) reports the grain, join and fanout decisions made by the compiler.

Catalog discovery now delays type binding until a query needs it and reuses a prepared compiler graph. On DuckDB 2.0.1 with 25 models and eight metrics per model, listing all semantic views went from 912 to 4 ms. Reading the nine columns and types of one model went from 860 to 19 ms. One semantic metric went from 4 to 5 ms. The benchmark verifies the returned rows and records all seven samples.

The community descriptor generator pins both supported DuckDB versions to a single source commit. Host coverage includes DuckFlight 0.2.1 and both parser load orders with Yardstick.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 28, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-28T18:45:16.814175Z 84eeb49 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 84eeb497c6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +542 to +544
if selected.is_none()
&& column["table"].is_null()
&& output_aliases.contains(&field.to_ascii_lowercase())

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve ORDER BY aliases that also name selected view fields

When an output alias also names a field exposed by the semantic view, this condition substitutes the view field instead of preserving the output alias. For example, after CREATE SEMANTIC VIEW sales AS SELECT country AS region, revenue AS gross FROM orders, SELECT gross AS region FROM sales ORDER BY region becomes an ordering by country. The downstream compiler then adds that dimension to the aggregation grain, returning country-level totals instead of the requested scalar total. Resolve unqualified ORDER BY output aliases before substituting view fields, including when the names collide.

Useful? React with 👍 / 👎.

Comment thread sqlctx-rs/src/ffi/catalog/views.rs Outdated
Comment on lines +532 to +535
} else if outer.len() == 1 {
outer.values().next().and_then(Option::as_ref)
} else {
None

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Resolve local view columns independently of inherited scopes

In a nested SELECT, outer includes both inherited relations and the current SELECT's sources because visit initializes its scope with outer.clone(). Consequently, an unrelated enclosing relation prevents unqualified columns from being expanded even when the inner SELECT has exactly one source. With sales exposing revenue AS gross, SELECT (SELECT gross FROM sales) AS total FROM main.raw_orders leaves the inner gross unchanged while replacing sales with its base model; compilation then fails because that model has no gross field. Track local sources separately and resolve them before considering enclosing scopes.

Useful? React with 👍 / 👎.

@nicosuave nicosuave closed this Nov 28, 2026
@nicosuave nicosuave reopened this Nov 28, 2026
@nicosuave
nicosuave added this pull request to stack #510 November 28, 2026 23:40
@nicosuave
nicosuave merged commit 7bacd63 into main Nov 29, 2026
40 checks passed
@nicosuave
nicosuave deleted the semantic-catalog-views branch November 29, 2026 16:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant